package com.hs.mpdemo_01.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hs.mpdemo_01.entity.Users;
import com.hs.mpdemo_01.mapper.UserMapper;
import com.hs.mpdemo_01.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName UserServiceImpl
 * @Description TODO
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper mapper;

    @Override
    public List<Users> findAll() {
        return mapper.selectList(null);
    }

    @Override
    public Page<Users> fidnByPage(Integer pageNum, Integer pageSize) {
        Page<Users> page = new Page<>(pageNum,pageSize);
        return mapper.selectPage(page, null);
    }

    @Override
    public int addUser(Users users) {
        return mapper.insert(users);
    }

    @Override
    public int updateUser(Users users) {

        return mapper.updateById(users);
    }

    @Override
    public int removeUser(Integer id) {
        return mapper.deleteById(id);
    }

    @Override
    public List<Users> findByCondition(Users users) {
        QueryWrapper<Users> wrapper = new QueryWrapper<>();
        wrapper.like("username",users.getUsername());
        return mapper.selectList(wrapper);
    }

    @Override
    public List<Users> findByLambda(Users users) {
        LambdaQueryWrapper<Users> wrapper =new LambdaQueryWrapper<>();
        wrapper.like(Users::getUsername,users.getUsername());
        return mapper.selectList(wrapper);
    }

    @Override
    public int removeById(Integer id) {
        return mapper.deleteById(id);
    }

    @Override
    public Users findByUsername(String username) {
        return mapper.selectByUsername(username);
    }


}
